package org.mspring.mlog.service;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.mspring.mlog.entity.Attachment;
import org.mspring.mlog.service.exception.StorageException;
import org.mspring.platform.dao.hibernate.IGenericDao;
import org.springframework.web.multipart.MultipartFile;

/**
 * 
 * @author Gao Youbo
 * @since 2013-06-18 16:34:42
 */
public interface AttachmentService extends IGenericDao<Attachment, java.lang.Long> {
    /**
     * 创建附件
     * 
     * @param mf
     *            附件文件
     * @param from
     *            附件来源
     * @return
     * @throws IOException
     * @throws StorageException
     */
    Attachment createAttachment(MultipartFile mf, String from) throws StorageException, IOException;

    /**
     * 创建附件
     * 
     * @param mf
     *            附件文件
     * @param from
     *            附件来源
     * @param fid
     *            附件来源编号
     * @return
     * @throws IOException
     * @throws StorageException
     */
    Attachment createAttachment(MultipartFile mf, String from, Long fid) throws StorageException, IOException;

    /**
     * 创建附件
     * 
     * @param is
     * @param extension
     * @param ftype
     * @param fkey
     * @return
     * @throws IOException
     * @throws StorageException
     */
    Attachment createAttachment(InputStream is, String extension, Long user, String from, Long fid) throws IOException, StorageException;

    /**
     * 查找文章对应的附件
     * 
     * @param post
     *            文章编号
     * @return
     */
    public List<Attachment> findAttachmentsByPost(Long post);

    /**
     * 查找twitter对应的附件
     * 
     * @param twitter
     *            twitter编号
     * @return
     */
    public List<Attachment> findAttachmentsByTwitter(Long twitter);

    /**
     * 根据附件来源编号查找该附件来源对应的附件
     * 
     * @param fid
     *            附件来源编号
     * @param from
     *            附件来源
     * @return
     */
    public List<Attachment> findAttachmentsByFid(Long fid, String from);

    /**
     * 删除附件
     * 
     * @param id
     */
    void deleteAttachment(Long id);

    /**
     * 设置附件来源
     * 
     * @param id
     *            附件编号
     * @param from
     *            附件来源
     * @param fid
     *            附件来源编号
     */
    void setAttachmentFid(Long id, String from, Long fid);

    /**
     * 删除附件
     * 
     * @param fid
     * @param from
     */
    void deleteAttachment(Long fid, String from);

}